package com.qidian.mes.qc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.pojo.Ipqc;
import com.qidian.mes.qc.mapper.IpqcMapper;
import com.qidian.mes.qc.service.IpqcService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class IpqcServiceImpl implements IpqcService {
    @Autowired
    private IpqcMapper  ipqcMapper;
    @Override
    public MESResult queryById(Long ipqcId) {
        Ipqc ipqc=null;
        if ((ipqc=ipqcMapper.selectById(ipqcId))!=null){
            return MESResult.ok(ipqc);
        }
        return MESResult.empty();
    }

    @Override
    public MESResult list(int page, int limit, Ipqc ipqc) {
        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page,limit);
        List<Ipqc> list =ipqcMapper.list(ipqc);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<Ipqc> pageInfo=new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult save(Ipqc ipqc) {
        ipqcMapper.save(ipqc);
        return MESResult.ok();
    }

    @Override
    public MESResult update(Ipqc ipqc) {
        ipqcMapper.update(ipqc);
        return  MESResult.ok();
    }

    @Override
    public MESResult deleteByIpqcId(Long ipqcId) {
        ipqcMapper.deleteByIpqcId(ipqcId);
        return MESResult.ok();
    }

    @Override
    public MESResult deletesByIpqcId(Long[] ipqcId) {
        int count= ipqcMapper.deletesByIpqcId(ipqcId);
        return MESResult.ok(count+"");
    }
}
